package com.smartleanx.module.hrm.service.esign.service.impl;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartleanx.module.hrm.dal.mysql.esign.HrmETaskFileMapper;
import com.smartleanx.module.hrm.service.esign.service.HrmETaskFileService;
import com.smartleanx.module.hrm.service.esign.temp.po.HrmETaskFile;
import com.smartleanx.module.hrm.util.esign.ESignUtil;
import com.smartleanx.module.hrm.util.esign.EsignHttpHelper;
import com.smartleanx.module.hrm.util.esign.EsignHttpResponse;
import com.smartleanx.module.hrm.util.esign.enums.EsignRequestType;
import com.smartleanx.module.hrm.util.esign.exception.EsignDemoException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * e签宝模板和底稿文件Service实现
 *
 * @author xzq
 * @since 2025-07-18 11:23:11
 */
@Service
public class HrmETaskFileServiceImpl extends ServiceImpl<HrmETaskFileMapper, HrmETaskFile> implements HrmETaskFileService {


    @Value("${esign.url}")
    private String esignUrl;

    @Override
    public void addSignFlowAttachment(String signFlowId, String fileId) {
        String apiaddr="/v3/sign-flow/"+signFlowId+"/attachments";
        System.out.println("请求路径:"+apiaddr);
        //请求方法
        EsignRequestType requestType= EsignRequestType.POST;

        //获取文件id以及文件上传地址

        JSONObject parram = new JSONObject();
        JSONArray attachmentList = new JSONArray();
        JSONObject item = new JSONObject();
        item.set("fileId",fileId);
//        item.set("fileName","0dba00d1258649c9bc9f082dd38cd799");
        attachmentList.add(item);
        parram.set("attachmentList",attachmentList);
        String jsonParm=parram.toString();

        //生成签名鉴权方式的的header
        try {
            ESignUtil.sendHttpResponse(jsonParm,requestType,apiaddr,esignUrl);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
